package edu.gyc.test;

import java.util.concurrent.ThreadPoolExecutor;

public class SingletonDemo {
    private static SingletonDemo singletonDemo=null;

    private SingletonDemo() {
        System.out.println(Thread.currentThread().getName()+"\t访问SingletonDemo构造方法");
    }

    public  static SingletonDemo getInstance() {
        if (singletonDemo == null) {
            synchronized (SingletonDemo.class) {
                if (singletonDemo == null) {
                    singletonDemo=new SingletonDemo();
                }
            }
        }
        return singletonDemo;
    }

    public static void main(String[] args) {
        /*
        System.out.println(SingletonDemo.getInstance()==SingletonDemo.getInstance());
        System.out.println(SingletonDemo.getInstance()==SingletonDemo.getInstance());
        System.out.println(SingletonDemo.getInstance()==SingletonDemo.getInstance());
*/
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                SingletonDemo.getInstance();

            }).start();
        }
    }
}
